/*
  Copyright 2007 Anders Båtstrand

      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

 */

package org.dyndns.anderlin.jmplayer.player;

import javazoom.jlgui.basicplayer.*;
import org.dyndns.anderlin.jmplayer.model.Track;

import java.util.Map;


public class JLGuiBasicPlayer extends AbstractPlayer implements BasicPlayerListener {

    BasicPlayer basicPlayer;

    public JLGuiBasicPlayer() {
        basicPlayer = new BasicPlayer();
        //basicPlayer.addBasicPlayerListener(this);
    }


    @Override
    public void setSong(Track song) {
        // try {
        //basicPlayer.open(song.getFile());
        super.setSong(song);
        // } catch (BasicPlayerException e) {
        //     e.printStackTrace();
        //}
    }

    public void play() throws Exception {
        basicPlayer.play();
        setState(PlayerState.PLAYING);
    }

    public void resume() {
        try {
            basicPlayer.resume();
            setState(PlayerState.PLAYING);
        } catch (BasicPlayerException e) {
            e.printStackTrace();
        }
    }

    public void pause() {
        try {
            basicPlayer.pause();
            setState(PlayerState.PAUSED);
        } catch (BasicPlayerException e) {
            e.printStackTrace();
        }
    }

    public void stop() {
        try {
            basicPlayer.stop();
            setState(PlayerState.STOPPED);
        } catch (BasicPlayerException e) {
            e.printStackTrace();
        }
    }

    public void opened(Object object, Map map) {
    }

    public void progress(int i, long l, byte[] bytes, Map map) {
    }

    public void stateUpdated(BasicPlayerEvent basicPlayerEvent) {
        // May be implement this?
    }

    public void setController(BasicController basicController) {
    }
}
